<?php
include("admin_check.php");
include_once("../function.php");
include_once("../class/bonus_class.php");
include_once("../class/member_class.php");
include_once("../class/ulevel_class.php");
header("Content-Type: text/html;charset=utf-8");
session_start();
checkqx(2,5);
#搜索会员
if ($_POST['Search']){
    $SearchContent=$_POST['SearchContent'];
    $TimeStart=$_POST['TimeStart'];
    $TimeEnd=$_POST['TimeEnd'];
    $SearchType=$_POST['SearchType'];
    if ($TimeStart!=NULL){
        if ($TimeEnd==NULL){
            $TimeEnd=now();
        }
        $_SESSION['SearchTime']="and udate>='".$TimeStart."' and udate<='".$TimeEnd."'";
    }else{
        $_SESSION['SearchTime']=NULL;
    }
    if ($SearchContent!=NULL){
        if ($SearchType==1){
            #搜索会员编号
            $_SESSION['Search']="and nickname='".$SearchContent."'";
        }
    }else{
        if ($SearchType==1){
            $_SESSION['Search']=NULL;
        }elseif($SearchType==2){
            #搜索未发放
            $_SESSION['Search']="and isgrant=0";
        }elseif($SearchType==3){
            #搜索已发放
            $_SESSION['Search']="and isgrant=1";
        }
    }
}else{
    if ($_GET['page']==NULL){
        $_SESSION['Search']=NULL;
        $_SESSION['SearchTime']=NULL;
    }
}

#充值确认
if ($_POST['button']){
    $cheuid_arr = $_POST['UID'];
    $_bonus=new bonus_class();
    $_member=new member_class();
    $_ulevel_class=new ulevel_class();
    foreach ((array)$cheuid_arr as $id)
    {
        $ulevelup=que_select_cl('ulevelup',$id);
        if ($ulevelup['issh']==0){
            $us=que_select_cl('member',$ulevelup['sid']);
            $ul=ulevel($ulevelup['uplevel']);
            $us_update['ulevel']=$ul['ulevel'];
            $us_update['lsk']=$ul['lsk'];
            $us_update['dan']=$ul['dan'];
            edit_update_cl('member',$us_update,$us['id']);
            $cc_xiugai['issh']=1;
            edit_update_cl('ulevelup',$cc_xiugai,$id);
            $shengyu=$_bonus->b1bonus($us['id'],$us['reid'],$ulevelup['cha']);
            $_member->addArea($us['id'],$us['treeplace'],$shengyu);
            $_systemyeji=new system_class();
            $_systemyeji->yejitongji(0,0,$ulevelup['cha'],0,0,0,0);

            $me=$_member->getMemberbyID($us['id']);
            $_ul=$_ulevel_class->getulevelbyulevel($me['ulevel']);
            $b5=$_ul['yl6']/100*$ulevelup['cha'];
            $me_update['b5']=$me['b5']+$b5;
            edit_update_cl('member',$me_update,$me['id']);

            $_bonus->xlevelup();
            $_bonus->addcfxf();
            $_bonus->b3bonus();
            $_bonus->b0bonus($me['id'],$me['nickname']);
        }
    }
    echo "<script language=javascript>alert('升级确认完成.');window.location.href='?'</script>";
}

#删除记录
if ($_GET['button3']){
    $cheuid_arr = $_GET['ID'];
        $ulevelup=que_select_cl('futou',$cheuid_arr);
        if($ulevelup['issh']==0){
            $cc_xiugai['issh']=2;
            edit_update_cl('futou',$cc_xiugai,$cheuid_arr);
            echo "<script language=javascript>alert('操作成功.');window.location.href='?'</script>";
        }else{
            echo "<script language=javascript>alert('已操作的不能再操作.');window.location.href='?'</script>";
        }




}#确认记录
if ($_GET['button2']){
    $_bonus=new bonus_class();
    $_member=new member_class();
    $_ulevel_class=new ulevel_class();
    $cheuid_arr = $_GET['ID'];
        $ulevelup=que_select_cl('futou',$cheuid_arr);
        if($ulevelup['issh']==0){
            $us=que_select_cl('member',$ulevelup['uid']);
            $ul=ulevel($ulevelup['uplevel']);
            $us_update['ulevel']=$ul['ulevel'];
            $us_update['lsk']=$ul['lsk'];
            $us_update['dan']=$ul['dan'];
            $us_update['mey']=0;
            $us_update['maxmey']=0;
            $us_update['gwb']=0;
            $us_update['zsq']=0;
            $us_update['pv']=0;
            $us_update['area1']=0;
            $us_update['area2']=0;
            $us_update['recount']=0;
            $us_update['yarea1']=0;
            $us_update['yarea2']=0;
            $us_update['fengding']=0;
            $us_update['futou']=0;
            $us_update['isxg']=0;
            $us_update['fenghao']=0;

            edit_update_cl('member',$us_update,$us['id']);
            $_member->addArea($us['id'],$us['treeplace'],$us['lsk']);
            $_bonus->b1bonus($us['id']);
            $_bonus->b3bonusd();
            $_bonus->b0bonus();

            $cc_xiugai['issh']=1;
            edit_update_cl('futou',$cc_xiugai,$cheuid_arr);

            echo "<script language=javascript>alert('操作成功.');window.location.href='?'</script>";
        }else{
            echo "<script language=javascript>alert('已操作的不能再操作.');window.location.href='?'</script>";
        }

}

?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="css/table.css" rel="stylesheet" type="text/css">
    <link href="css/style.css" rel="stylesheet" type="text/css">
    <script src="../js/calendar.js"></script>
    <link href="../layui-master/dist/css/layui.css" rel="stylesheet" type="text/css">
    <script src="../layui-master/dist/layui.js"></script>
    <link href="../layui-master/dist/css/layui.css" rel="stylesheet" type="text/css">
    <script src="../js/calendar.js"></script>
    <script src="../layui-master/dist/layui.js"></script>
    <script>
        layui.use('laydate', function(){
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#TimeStart' //指定元素
            });
            laydate.render({
                elem: '#TimeEnd' //指定元素
            });
        });
    </script>
    <title>升级申请</title>
    <SCRIPT LANGUAGE=javascript>
        <!--
        function SelectAll() {
            for (var i=0;i<document.form1.UID.length;i++) {
                var e=document.form1.UID[i];
                e.checked=!e.checked;
            }
        }
        -->
    </script>
    <script language="javascript">
        <!--
        //导出excel
        function exportExcel(DivID){
            //先声明Excel插件、Excel工作簿等对像
            var jXls, myWorkbook, myWorksheet;

            try {
                //插件初始化失败时作出提示
                jXls = new ActiveXObject('Excel.Application');
            }catch (e) {
                alert("无法启动Excel!\n\n如果您确信您的电脑中已经安装了Excel，"+"那么请调整IE的安全级别。\n\n具体操作：\n\n"+"工具 → Internet选项 → 安全 → 自定义级别 → 对没有标记为安全的ActiveX进行初始化和脚本运行 → 启用");
                return false;
            }

            //不显示警告
            jXls.DisplayAlerts = false;

            //创建AX对象excel
            myWorkbook = jXls.Workbooks.Add();
            //myWorkbook.Worksheets(3).Delete();//删除第3个标签页(可不做)
            //myWorkbook.Worksheets(2).Delete();//删除第2个标签页(可不做)

            //获取DOM对像
            var curTb = document.getElementByIdx_x(DivID);

            //获取当前活动的工作薄(即第一个)
            myWorksheet = myWorkbook.ActiveSheet;

            //设置工作薄名称
            myWorksheet.name="NP统计";

            //获取BODY文本范围
            var sel = document.body.createTextRange();

            //将文本范围移动至DIV处
            sel.moveToElementText(curTb);

            //选中Range
            sel.select();

            //清空剪贴板
            window.clipboardData.setData('text','');

            //将文本范围的内容拷贝至剪贴板
            sel.execCommand("Copy");

            //将内容粘贴至工作簿
            myWorksheet.Paste();

            //打开工作簿
            jXls.Visible = true;

            //清空剪贴板
            window.clipboardData.setData('text','');
            jXls = null;//释放对像
            myWorkbook = null;//释放对像
            myWorksheet = null;//释放对像
        }
        -->
    </script>
</head>
<body>
<form name="form1" method="post" action="?">
    <table width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="layui-table" lay-skin="line">
        <tr >
            <td height="4" colspan="8" align="left">
                <select name="SearchType" id="SearchType">
                    <option value="1">会员编号</option>
                </select>
                <input type="text" name="SearchContent" id="SearchContent">
                <input type="submit" name="Search" id="Search" class="layui-btn layui-btn-small" value="搜索"></td>
        </tr>
        <tr>
            <td height="5" colspan="9" align="left">搜索时间范围：
                <input type="text" name="TimeStart" id="TimeStart" style="width:100px" >
                至
                <input type="text" name="TimeEnd" id="TimeEnd" style="width:100px" ></td>
        </tr>

        <div id="daochu">
            <tr >
                <td colspan="10" align="center">复 投 申 请</td>
            </tr>
            <tr>

                <td align="center">复投会员编号</td>
                <td align="center">复投会员姓名</td>
                <!--        <td align="center">原级别</td>
                        <td align="center">申请级别</td>-->
                <td align="center">复投金额</td>
                <td align="center">申请时间</td>
                <td align="center">操作人编号</td>
                <td colspan="2" align="center">操作人姓名</td>
                <td  align="center">审核状态</td>
                <td  align="center">操作</td>
            </tr>
            <?php
            $pagesize = 20; //设置每页记录数
            $sql = "SELECT * FROM `futou` WHERE 1=1 ".$_SESSION['Search']." ".$_SESSION['SearchTime']."";
            if($query = mysql_query($sql)){
                $sum = mysql_num_rows($query); //计算总记录数
            }else{
                $sum=0;
            }
            if($sum % $pagesize == 0) //计算总页数
                $total = (int)($sum/$pagesize);
            else
                $total = (int)($sum/$pagesize) + 1;
            if (isset($_GET['page'])) //获得页码
            {
                $p = (int)$_GET['page'];
            }
            else
            {
                $p = 1;
            }
            if ($p>$total){
                $p=$total;
            }
            $start = $pagesize * ($p - 1); //计算起始记录
            $sql = "SELECT * FROM `futou` WHERE 1=1 ".$_SESSION['Search']." ".$_SESSION['SearchTime']." order by udate desc limit ".$start.",".$pagesize;
            if($query = mysql_query($sql)){
                while ($row=mysql_fetch_array($query)){
                    $yul=ulevel($row['ylevel']);
                    $uul=ulevel($row['uplevel']);
                    ?>
                    <tr>

                        <td align="center"><?=$row['snickname']?></td>
                        <td align="center"><?=$row['susername']?></td>
                        <!--        <td align="center"><?/*=$yul['lvname']*/?></td>
        <td align="center"><?/*=$uul['lvname']*/?></td>-->
                        <td align="center"><?=$row['cha']?></td>
                        <td align="center"><?=$row['udate']?></td>
                        <td align="center"><?=$row['nickname']?></td>
                        <td colspan="2" align="center"><?=$row['username']?></td>
                        <td  align="center"><?php if ($row['issh']==1){?>通过审核<?php }elseif ($row['issh']==2){?>未通过审核<?php }else {?> <font color="#FF0000">未审核</font><?php }?></td>
                        <td align="center">
                            <input type="button"  class="layui-btn layui-btn-small layui-btn-normal" id="button" name="button2" value="通过" onClick="window.location.href='admin_futou.php?ID=<?=$row['id']?>&button2=1'" />
                            <input type="button"  class="layui-btn layui-btn-small layui-btn-normal" id="button" name="button2" value="不通过" onClick="window.location.href='admin_futou.php?ID=<?=$row['id']?>&button3=1'" />
                        </td>

                        </tr>
                    <?php
                }
            }
            ?>
        </div>
        <tr>
            <td height="21" colspan="11" align="right">
                <table width="100%" border="0">
                    <tr >
                        <td align="right"><?php echo fenye($p,$pagesize,$sum,$total,$cx)?></td>
                    </tr>
                </table></td>
        </tr>
    </table>
</form>
</body>
</html>